<?php
session_start();
include_once'config/config.php';
echo md5('123456');die;

if($_POST){

  $qcode = $_POST['qcode'];

  // 设置验证码过期时间
  $expires = 10*60*1000;

  // 检测验证码是否过期
  if(time() - $_SESSION['expires'] > $expires){
    show_msg('验证码已过期');
  }

  //检测验证码是否错误
  if(strtolower($qcode) != $_SESSION['qcode']){
    show_msg('验证码错误');
  }

  $admin_username = $_POST['admin_username'];
  $admin_password = md5($_POST['admin_password']);

  $r = getOne('admin',"admin_username = '${admin_username}' and admin_password = '${admin_password}'");
  if($r){
    //给变量赋值
    $_SESSION['admin']=$admin_username;
    $_SESSION['last_time'] = $r['last_time'];
    $data = array();
    $data['last_time'] = time();
    update('admin',$data,"admin_username = '{$admin_username}'");
    show_msg('登录成功','index.php');
  }else{
    show_msg('登录失败','login.php');
  }
}
?>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<title>登录</title>
<meta name="keywords" content="Admin">
<meta name="description" content="Admin">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- Core CSS  -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">

<!-- Theme CSS -->
<link rel="stylesheet" type="text/css" href="css/theme.css">
<link rel="stylesheet" type="text/css" href="css/pages.css">
<link rel="stylesheet" type="text/css" href="css/responsive.css">

</head>
<body class="login-page">

<!-- Start: Main -->
<div id="main">
<div class="container">
<div class="row">
  <div id="page-logo"></div>
</div>
<div class="row">
  <div class="panel">
    <div class="panel-heading">
      <div class="panel-title">系统登录入口</div>
    </div>

    <form action="" class="cmxform" id="altForm" method="post">
      <div class="panel-body">

        <div class="form-group">
          <div class="input-group"> <span class="input-group-addon">用户名</span>
            <input type="text" name="admin_username" class="form-control" autocomplete="off"  placeholder="请输入您的用户名">
          </div>
        </div>

        <div class="form-group">
          <div class="input-group"> <span class="input-group-addon">密&nbsp;&nbsp;&nbsp;码</span>
            <input type="password" name="admin_password" class="form-control" autocomplete="off" placeholder="请输入您的密码">
          </div>
        </div>

        <div class="form-group">
          <div class="input-group"> <span class="input-group-addon">验证码</span>
            <input type="text" name="qcode" class="form-control" autocomplete="off" placeholder="请输入验证码">
            <br>
            <div class="code">
              <img src="<?php echo HTTP.'admin/lib/imgcode.php'?>">
            </div>
          </div>
        </div>

      </div>

      <div class="panel-footer"> <span class="panel-title-sm pull-left" style="padding-top: 7px;"></span>
      <div class="form-group margin-bottom-none">
        <input type="hidden" value="login" name="action-mark" />
        <input class="btn btn-primary pull-right" type="submit" value="登 录" />
        <div class="clearfix"></div>
      </div>
      </div>

    </form>

  </div>
</div>
</div>
</div>
<!-- End: Main --> 

<script type="text/javascript">
  $('.code img').click(function(){
    var d = new Date();

    $(this).attr('src','<?php echo HTTP."admin/lib/imgcode.php?t=";?>'+d.getTime());
  })
</script>
</body>

</html>